package com.xnyzc.lhy.gateway.controller;


import com.xnyzc.lhy.common.component.redis.RedisCommon;
import com.xnyzc.lhy.common.entity.Rv;
import com.xnyzc.lhy.common.penum.EErrorCode;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/redis")
public class RedisController {

    @Autowired
    private RedisCommon redisCommon;



    /**
     * 根据key,清理redis缓存
     *
     * @return
     */
    @PostMapping("/clearByKey")
    public Rv clearByKey(String key) {
        if (StringUtils.isBlank(key)) {
            return Rv.error(EErrorCode.missingArg);
        }

        boolean isRemove = redisCommon.remove(key);
        return isRemove ? Rv.wrap(null) : Rv.error(EErrorCode.clearRedis);
    }
}
